package com.jack006.article.task;

import com.jack006.article.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

/**
 * @Classname TaskPublishArticles
 * @Description 文章定时任务
 * @Date 2021-07-09 21:52
 * @Created by jack
 */
//@Configuration
//@EnableScheduling
public class TaskPublishArticles {

    @Autowired
    private ArticleService articleService;

    /**
     * 添加定时任务
     */
    @Scheduled(cron = "0/10 * * * * ?")
    private void publishArticles(){
        System.out.println("执行定时任务:"+ LocalDateTime.now());

        // 调用文章 Service,把当前时间应该发布的定时文章
        articleService.updateAppointToPublish();

        System.out.println("完成执行定时任务:");
    }
}
